home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCP / UUSUB.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  11KB  |  326 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u s u b . c                                                   */
  3. /*                                                                    */
  4. /*    Report summary of UUPC activity                                 */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Copyright (c) 1990-1993 by Kendra Electronic Wonderworks        */
  9. /*                                                                    */
  10. /*    All rights reserved except those explicitly granted by the      */
  11. /*    UUPC/extended license agreement.                                */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. /*--------------------------------------------------------------------*/
  15. /*                          RCS Information                           */
  16. /*--------------------------------------------------------------------*/
  17.  
  18. /*
  19.  *    $Id: uusub.c 1.6 1993/10/03 20:43:08 ahd Exp $
  20.  *
  21.  *    $Log: uusub.c $
  22.  * Revision 1.6  1993/10/03  20:43:08  ahd
  23.  * Normalize comments to C++ double slash
  24.  *
  25.  * Revision 1.5  1993/07/06  11:02:06  ahd
  26.  * Load host status information after parsing args
  27.  *
  28.  * Revision 1.4  1993/05/09  12:44:25  ahd
  29.  * Reset collection time start before writing it out to disk
  30.  *
  31.  * Revision 1.3  1993/04/11  00:35:46  ahd
  32.  * Global edits for year, TEXT, etc.
  33.  *
  34.  * Revision 1.2  1992/11/19  03:03:24  ahd
  35.  * drop rcsid
  36.  *
  37.  */
  38.  
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <time.h>
  44.  
  45. #include "lib.h"
  46. #include "hostable.h"
  47. #include "dater.h"
  48. #include "hostrset.h"
  49. #include "hostatus.h"
  50. #include "getopt.h"
  51. #include "security.h"
  52. #include "timestmp.h"
  53.  
  54. /*--------------------------------------------------------------------*/
  55. /*                            Local macros                            */
  56. /*--------------------------------------------------------------------*/
  57.  
  58. #define line( a, b, c, d, e, f, g, h, i, j ) \
  59.       printf("%-8.8s %-6.6s %-11.11s %-11.11s %5.5s %5.5s %5.5s %5.5s %5.5s %5.5s\n" ,\
  60.       a, b, c, d, e, f, g, h, i ,j )
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*                        Internal prototypes                         */
  64. /*--------------------------------------------------------------------*/
  65.  
  66. static void showstats( const char *name );
  67. static void showhost( struct HostTable *host);
  68. static char *when( time_t t );
  69. static char *status( hostatus current_status );
  70. static char *format( long l);
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*                          Global variables                          */
  74. /*--------------------------------------------------------------------*/
  75.  
  76. static char output[10 * 12];
  77. static size_t column ;
  78.  
  79. currentfile();
  80.  
  81. /*--------------------------------------------------------------------*/
  82. /*    u s a g e                                                       */
  83. /*                                                                    */
  84. /*    Report flags used by program                                    */
  85. /*--------------------------------------------------------------------*/
  86.  
  87. static         void    usage(void)
  88. {
  89.       fprintf(stderr, "Usage: uusub\t[-c] [-s <nodename>] [-x debug]\n");
  90. }
  91.  
  92. /*--------------------------------------------------------------------*/
  93. /*                            main program                            */
  94. /*--------------------------------------------------------------------*/
  95.  
  96. #ifdef __TURBOC__
  97. #pragma argsused
  98. #endif
  99.  
  100. void main( int argc , char **argv)
  101. {
  102.  
  103.    int         option;
  104.    boolean clear_stats = FALSE;
  105.    char *name = nil(char);
  106.  
  107. /*--------------------------------------------------------------------*/
  108. /*               Announce ourselves to a waiting world                */
  109. /*--------------------------------------------------------------------*/
  110.  
  111.    debuglevel = 0;
  112.  
  113. #if defined(__CORE__)
  114.    copywrong = strdup(copyright);
  115.    checkref(copywrong);
  116. #endif
  117.  
  118.    banner( argv );
  119.  
  120. /*--------------------------------------------------------------------*/
  121. /*                        Process option flags                        */
  122. /*--------------------------------------------------------------------*/
  123.  
  124.    while ((option = getopt(argc, argv, "cs:x:")) != EOF)  {
  125.       switch(option)  {
  126.          case 'c':               // clear stats
  127.             clear_stats = TRUE;
  128.             break;
  129.          case 's':               // only named host
  130.             name = optarg;
  131.             break;
  132.          case 'x':
  133.             debuglevel = atoi(optarg);
  134.             break;
  135.          default:
  136.             usage();
  137.             exit(1);
  138.             break;
  139.       }
  140.    }
  141.  
  142.    if (optind != argc)
  143.    {
  144.       puts("Extra parameter(s) at end.");
  145.       exit(4);
  146.    }
  147.  
  148. /*--------------------------------------------------------------------*/
  149. /*       Load system configuration and then the UUPC host stats       */
  150. /*--------------------------------------------------------------------*/
  151.  
  152.    if (!configure( B_UUSTAT ))
  153.       panic();
  154.  
  155.    HostStatus();
  156.  
  157. /*--------------------------------------------------------------------*/
  158. /*            Now display or clear the loaded information             */
  159. /*--------------------------------------------------------------------*/
  160.  
  161.    if ( (name != NULL) && (checkreal( name ) == BADHOST) )
  162.        printf("Unknown host \"%s\"\n", name );
  163.    else if (clear_stats)
  164.    {
  165.        if ( name == NULL )
  166.          time( &start_stats );
  167.        HostReset((const char *)name);
  168.    }
  169.    else
  170.        showstats((const char *)name);
  171.  
  172. } /* main */
  173.  
  174. /*--------------------------------------------------------------------*/
  175. /*    s h o w s t a t s                                               */
  176. /*                                                                    */
  177. /*    Display information on all hosts                                */
  178. /*--------------------------------------------------------------------*/
  179.  
  180. static void showstats( const char *name )
  181. {
  182.    struct HostTable *host;
  183.    boolean firsthost = TRUE;
  184.    static const char *dashes = "-----------";
  185.  
  186.    printf("Host information collected since %s\n",ctime( &start_stats ));
  187.  
  188.    line("Host","Host ",  "Date Last",  "Last Conn","Secs" , "Bytes", "Bytes",
  189.          "Files", "Files", "Total");
  190.    line("Name","Status ","Connected ","Attempt", "Conn",  "Sent",  "Recvd",
  191.         "Sent",  "Recvd", "Errs");
  192.    line(dashes,dashes,dashes,dashes,dashes,dashes,dashes,dashes,
  193.          dashes,dashes);
  194.  
  195.    if (name != NULL)
  196.       showhost ( checkreal(name) );
  197.    else
  198.       while  ((host = nexthost( firsthost )) != BADHOST)
  199.       {
  200.          firsthost = FALSE;
  201.          showhost ( host );
  202.       } /* while */
  203.  
  204. } /* showstats */
  205.  
  206. /*--------------------------------------------------------------------*/
  207. /*    s h o w h o s t                                                 */
  208. /*                                                                    */
  209. /*    Display information on a single host                            */
  210. /*--------------------------------------------------------------------*/
  211.  
  212. static void showhost( struct HostTable *host)
  213. {
  214.    column = 0;
  215.    checkref( host->hstats );
  216.    line( host->hostname,
  217.       status( host->hstatus ),
  218.       when( host->hstats->lconnect ),
  219.       when( host->hstats->ltime ),
  220.       format( host->hstats->connect ),
  221.       format( host->hstats->bsent ),
  222.       format( host->hstats->breceived ),
  223.       format( host->hstats->fsent ),
  224.       format( host->hstats->freceived ),
  225.       format( host->hstats->errors  ));
  226. } /* showhost */
  227.  
  228. /*--------------------------------------------------------------------*/
  229. /*                            Subroutines                             */
  230. /*--------------------------------------------------------------------*/
  231.  
  232. static char *when( time_t t )
  233. {
  234.    column += 13;
  235.    return dater( t, &output[column]);
  236. } /* whe